<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title>找回密码</title>
		<link rel="stylesheet" href="css/muse-ui.css">
		<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700,400italic">
		<link rel="stylesheet" href="https://cdn.bootcss.com/material-design-icons/3.0.1/iconfont/material-icons.css">
		<link rel="stylesheet" href="css/muse-ui-loading.css">
		<link rel="stylesheet" href="https://at.alicdn.com/t/font_951857_sr7zod4vu4.css">
		<script src="js/vue.min.js"></script>
		<script src="js/muse-ui.js"></script>
		<script src="js/muse-ui-loading.js"></script>
		<script src="js/muse-ui-toast.js"></script>
		<script src="js/axios.min.js"></script>
		<script src="js/mui.min.js"></script>
		<script src="js/utils.js"></script>
		<style>
			.container{
				height:calc(100vh);
				width: 100%;
				padding: 20px;
			}
			.container input {
				color: #ff4081;
			}
			.login-head{
				margin-top: 20%;
				width: 100%;
				text-align: center;
			}
			.icon-denglu{
				color: #fff;
				font-size: 70px;
			}
		</style>
	</head>
	<body>
		<div id="body">
			<mu-appbar style="width: 100%;position: fixed;top: 0;" color="secondary">
				<mu-button icon slot="left" @click="util.back()">
					<mu-icon value="arrow_back"></mu-icon>
				</mu-button>
				找回密码
			</mu-appbar>
			<mu-container style="padding-top: 56px;">
				<mu-text-field v-model="phone" type="number" label="手机号码" label-float full-width color="secondary"></mu-text-field><br />
				<div style="display: flex;justify-content: space-between;align-items: center;">
					<mu-text-field v-model="code" type="number" label="验证码" label-float color="secondary">
					</mu-text-field>
					<mu-button color="secondary" flat @click="getCode()" v-if="countDownNumber==0">获取验证码</mu-button>
					<mu-button color="secondary" flat v-else disabled>{{countDownNumber}}S</mu-button>
				</div>
				<br />
				<mu-text-field v-model="newPassword" type="password" label="新密码" label-float full-width color="secondary"></mu-text-field><br />
				<mu-text-field v-model="repeatPassword" type="password" label="重复密码" label-float full-width color="secondary"></mu-text-field><br />
				<mu-button color="secondary" full-width @click="changePassword">立即修改
					<mu-icon value="arrow_forward" right></mu-icon>
				</mu-button>
			</mu-container>
		</div>
	</body>
	<script type="text/javascript">
		var vm = new Vue({
			el: "#body",
			data() {
				return {
					phone: "",
					code: "",
					newPassword: "",
					repeatPassword: "",
					countDownNumber:"",
					getCodeNumber: ""
				}
			},
			methods: {
				changePassword(){
					var phone = this.phone;
					var code = this.code;
					var newPassword = this.newPassword;
					var repeatPassword = this.repeatPassword;
					if(!phone) {
						util.tip("请输入手机号");
						return;
					}
					if(!code) {
						util.tip("请输入验证码");
						return;
					}
					if(code != this.countDownNumber) {
						util.tip("验证码错误");
						return;
					}
					if(!newPassword) {
						util.tip("请输入新密码");
						return;
					}
					if(this.newPassword.length<6||this.newPassword.length>18){
						util.tip("密码长度在6至18位!");
						return;
					}
					if(!repeatPassword) {
						util.tip("请输入重复密码");
						return;
					}
					if(newPassword != repeatPassword) {
						util.tip("两次密码不一致");
						return;
					}
					var params = {
						"phone": phone,
						"password": newPassword,
					}
					util.httpSend("/rbac/forgetPassword", params, function(data) {
						if(data.code==1){
							alert(data.msg);
							util.back();
						}else{
							util.tip(data.msg);
						}
					},true)
				},
				getCode() {
					if (this.phone.length != 11) {
						util.tip("请输入正确的手机号!");
						return;
					}
					var params = {
						phone: this.phone
					}
					util.ajax("/rbac/makeRegCode", params, data => {
						util.tip(data.msg);
						this.getCodeNumber = data.object;
						this.countDownNumber = 60;
						var timer = setInterval(()=>{
							if(this.countDownNumber==0){
								clearInterval(timer)
							}else{
								this.countDownNumber--;
							}
						},1000)
					})
				},
			}
		})
		document.addEventListener('plusready', function() {});
	</script>
</html>
